import 'dart:math';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wan_android_flutter/common/base/base_page.dart';
import 'package:wan_android_flutter/common/resources/text_styles.dart';
import 'package:wan_android_flutter/common/routes/route_manager.dart';
import 'package:wan_android_flutter/common/widget/material_layout.dart';
import 'package:wan_android_flutter/generated/locales.g.dart';

import '../common_web/common_web_state.dart';
import 'hot_logic.dart';

class HotPage extends BasePage<HotLogic> {
  HotPage({super.key});

  @override
  String title() {
    return LocaleKeys.hot.tr;
  }

  @override
  Widget buildContent(BuildContext context) {
    return Container(
      color: colorData.bgWhite,
      width: double.infinity,
      padding: const EdgeInsets.symmetric(horizontal: 16),
      child: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Text(
              LocaleKeys.hot_search.tr,
              style: colorData.textBlack.s24.regular,
            ),
          ),
          const SliverPadding(padding: EdgeInsets.only(bottom: 16)),
          SliverToBoxAdapter(child: Obx(() {
            return Wrap(
              spacing: 10,
              runSpacing: 10,
              children: logic.state.hotWords.map((element) {
                return Container(
                  clipBehavior: Clip.hardEdge,
                  decoration: BoxDecoration(
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                      border: Border.all(
                          color: Color.fromRGBO(
                            Random().nextInt(256),
                            Random().nextInt(256),
                            Random().nextInt(256),
                            1,
                          ),
                          width: 1.5),
                      color: colorData.bgWhite),
                  child: MaterialLayout(
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                      onPressed: () {
                        Get.toNamed(RouteManager.searchResultPage, arguments: element.name ?? "");
                      },
                      backgroundColor: colorData.bgWhite,
                      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
                      child: Text(
                        element.name ?? "",
                        style: colorData.textBlack.s16.regular,
                      )),
                );
              }).toList(),
            );
          })),
          const SliverPadding(padding: EdgeInsets.only(bottom: 24)),
          SliverToBoxAdapter(
            child: Text(
              LocaleKeys.hot_web.tr,
              style: colorData.textBlack.s24.regular,
            ),
          ),
          const SliverPadding(padding: EdgeInsets.only(bottom: 16)),
          SliverToBoxAdapter(child: Obx(() {
            return Wrap(
              spacing: 10,
              runSpacing: 10,
              children: logic.state.hotWebs.map((element) {
                return Container(
                  decoration: BoxDecoration(
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                      border: Border.all(
                          color: Color.fromRGBO(
                            Random().nextInt(256),
                            Random().nextInt(256),
                            Random().nextInt(256),
                            1,
                          ),
                          width: 1.5),
                      color: colorData.bgWhite),
                  child: MaterialLayout(
                      backgroundColor: colorData.bgWhite,
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                      onPressed: () {
                        CommonBrowserParam commonBrowserParam = CommonBrowserParam(
                          title: element.name ?? "",
                          url: element.link ?? "",
                        );
                        Get.toNamed(RouteManager.commonWebPage, arguments: commonBrowserParam);
                      },
                      padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
                      child: Text(
                        element.name ?? "",
                        style: colorData.textBlack.s16.regular,
                      )),
                );
              }).toList(),
            );
          })),
          const SliverPadding(padding: EdgeInsets.only(bottom: 16)),
        ],
      ),
    );
  }
}
